package com.nineclock.sign.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignDepDTO;
import com.nineclock.sign.dto.SignUserDTO;
import com.nineclock.sign.dto.SignUserListDTO;
import com.nineclock.sign.service.SignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

@RestController
@Api(value = "签到接口", tags = "签到服务")
public class SignController {
    @Autowired
    private SignService signService;

    /**
     * APP: 获取当前用户当天签到次数
     * Tag ：王炳涛
     * 接口路径：GET/sign/getDayCount
     */
    @ApiOperation("APP: 获取当前用户当天签到次数")
    @GetMapping("/getDayCount")
    public Result<Integer> getDayCount() {
        Integer dayCount = signService.getDayCount();

        return Result.success(dayCount);
    }

    /**
     * APP: 查询本月签到记录
     * Tag ：王炳涛
     * 接口路径：GET/sign/pagingSignCurrentUserByMonth
     */
    @ApiOperation("APP: 查询本月签到记录")
    @GetMapping("pagingSignCurrentUserByMonth")
    public Result<List<SignUserDTO>> pagingSignCurrentUserByMonth(String dateStr) {

        List<SignUserDTO> signUserDTOList = signService.pagingSignCurrentUserByMonth(dateStr);
        return Result.success(signUserDTOList);
    }

    /**
     * APP: 签到
     * Tag : 杨定康
     * 接口路径：POST/sign/insert
     */
    @ApiOperation("APP: 签到")
    @PostMapping("insert")
    public Result insert(SignUserDTO signUserDTO) throws FileNotFoundException {
        signService.sign(signUserDTO);
        return Result.success();
    }

    /**
     * APP: 获取团队员工打卡列表
     * Tag ：黄佳洋
     * 接口路径：GET/sign/listSignAllUser
     */
    @ApiOperation("APP: 获取团队员工打卡列表")
    @GetMapping("listSignAllUser")
    public Result<List<SignUserListDTO>> listSignAllUser(String dateStr){
        List<SignUserListDTO> signUserListDTOList = signService.listSignAllUser(dateStr);
        return Result.success(signUserListDTOList);
    }

    /**
     * PC: 导出签到列表
     * Tag ：王子
     * 接口路径：GET/sign/export
     */
    @ApiOperation("PC: 导出签到列表")
    @GetMapping("export")
    public void export(@RequestParam String startTime, @RequestParam String endTime) throws IOException {
        signService.export(startTime, endTime);
    }

    /**
     * PC: 查询签到列表
     * Tag :王子
     * 接口路径：GET/sign/sign
     */
    @ApiOperation("PC: 查询签到列表")
    @GetMapping("sign")
    public Result<PageResult<SignDepDTO>> sign(@RequestParam(defaultValue = "1") Long page,
                                               @RequestParam(defaultValue = "7") Long pageSize,
                                               @RequestParam String startTime,
                                               @RequestParam String endTime) {
        PageResult<SignDepDTO> result = signService.sign(page, pageSize, startTime, endTime);
        return Result.success(result);
    }
    /**
     * PC-直接导入员工签到数据
     * Tag : 王子
     * 接口路径：POST/sign/uploadExcel
     */
    @ApiOperation("PC-直接导入员工签到数据")
    @PostMapping("uploadExcel")
    public Result uploadExcel(MultipartFile excelFile) throws Exception{
        signService.importData(excelFile);
        return Result.success();
    }

}
